showLoading()
var uzmoduledemo = null;
var phone = readData(localStorage.phone);
var guideId = readData(localStorage.guideId);
var db = openDatabase('messageChat', '1.0', 'messageChatOfHistory DB', 4 * 1024 * 1024);

function circle($scope, $http) {
	$scope.circleName = readData(localStorage.circleName).split('-')[0];	
	$scope.circleId = readData(localStorage.groupId)
	//获取圈子成员
	url = getUrl("48circleMember");
	header = getHeader();
	params = 'userId=' + readData(localStorage.guideId);
	$http({
		method: 'POST',
		url: url,
		headers: header,
		timeout: 10000,
		//cache: true,
		data: params
	}).success(function(data, status, headers, config) {
		if (data.obj) {			
			if (data.obj.isChat == 1) {
				$scope.hidefriendlist = false;
				//支持聊天
			} else {
				$scope.hidefriendlist = true;
			}
			for (var i in data.obj.list) {
				if (data.obj.list[i].account == readData(localStorage.phone)) {
					data.obj.list[i].hide = true;
				} else {
					data.obj.list[i].hide = false || $scope.hidefriendlist;
				}
			}
			$scope.members = data.obj.list;
			//判断成员头像是否为空
			$scope.daogou = data.obj.user;
			unreadNum(readData(localStorage.groupId),3);//获取群未读消息
			unreadNum($scope.daogou.id,1);//获取导购未读消息
			if (!$scope.daogou.headImg) {
				$scope.daogou.headImg = "../../image/my/pl_tp.png";
			}
			for (var i = 0; i < $scope.members.length; i++) {
				if (!$scope.members[i].headimg || $scope.members[i].headimg == 'null') {
					$scope.members[i].headimg = "../../image/my/pl_tp.png";
				}
				unreadNum($scope.members[i].id,1);//获取好友未读消息
			}
		} else {
			$scope.members = []
			$scope.daogou = {}
		};
		removeLoading()
	}).error(function() {
		removeLoading()
		console.log("chatlist is erro");
	});

	function unreadNum(targetId,type) {		   
		db.transaction(function(tx) {
			tx.executeSql('SELECT * FROM CurentOtherMessage WHERE Id=? AND Phone=? AND MessageType=? AND GuideId=?', [targetId, phone, type, guideId], function(tx, results) {
				var len = results.rows.length;
				if (len > 0) {
					var content=document.getElementById(targetId);
					content.innerHTML=len;
					content.style.display = 'block';
					if(len >= 99){
						content.innerHTML= '99+';
						content.style.fontSize = 9 + 'px';
					}
				}
			}, null);
		});
	}
	//打开对话窗口
	$scope.openChatGroup = function(circleId) {
		document.getElementById(circleId).style.display = 'none';
		localStorage.chatName = writeData('groupChat');
		localStorage.mem = writeData(JSON.stringify($scope.members));
		var mes = {};
		if (localStorage.mem) {
			mes = eval('(' + readData(localStorage.mem) + ')')
		}
		if ($scope.daogou) {
			mes.push($scope.daogou)
		}
		localStorage.mem = writeData(JSON.stringify(mes));
		mui.openWindow({
			url: '../chat/groupChat.html',
			id: 'groupChat.html'
		});
	}
	$scope.openChat = function(mem) {
		var memMy;
		localStorage.chatName = writeData('friendChat');
		if ($scope.members) {
			for (var i = 0; i < $scope.members.length; i++) {
				if ($scope.members[i]['huanid'] == readData(localStorage.huanId)) {
					memMy = $scope.members[i]
				}
			}
		}
		localStorage.mem = writeData(JSON.stringify(mem));
		localStorage.memMy = writeData(JSON.stringify(memMy));
		document.getElementById(mem.id).style.display = 'none';
		mui.openWindow({
			url: '../chat/friendChat.html',
			id: 'friendChat.html'
		});
	}
}

function getelement(elementid, num) {
	var ele = document.getElementById(elementid);
	if (num > 99) {
		ele.innerHTML = 99 + '..';
		ele.style.fontSize = 9 + 'px';
	} else {
		ele.innerHTML = num;
	}
	ele.style.display = 'block';
}